<template>
  <!-- 勘探任务分配列表 -->
  <div class="app-container">
    <!-- 搜索查询 -->
    <div class="form-container">
      <el-form ref="queryForm" :inline="true" label-width="90px" :model="filters">
        <el-form-item label="勘探点编号" prop="explorationCode">
          <el-input
            v-model="filters.explorationCode"
            size="small"
            placeholder="请输入勘探点编号"
            clearable
          />
        </el-form-item>
        <el-form-item label="勘探点类型" prop="drillHole">
          <el-select
            v-model="filters.drillHole"
            size="small"
            filterable
            placeholder="请选择勘探点类型"
            clearable
          >
            <el-option
              v-for="dict in explorationTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="勘探点状态" prop="explorationStatus">
          <el-select
            v-model="filters.explorationStatus"
            size="small"
            filterable
            placeholder="请选择勘探点状态"
            clearable
          >
            <el-option
              v-for="dict in explorationStatus"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <!--操作按钮-->
    <el-row :gutter="10" class="btns-group">
      <el-col :span="1.5">
        <el-button v-clickForbidden icon="el-icon-search" size="middle" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-clickForbidden icon="el-icon-refresh" size="middle" @click="resetQuery">重置</el-button>
      </el-col>
      <el-dropdown @command="handleEquipment">
        <span class="el-dropdown-link" :class="single ? 'is-disabled': ''"><i class="el-icon-user" /> 分配设备<i class="el-icon-arrow-down el-icon--right" /> </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item v-for="(item, index) in EquipmentTypeList" :key="index" :disabled="single" :command="beforeHandleCommand(item)">
            {{ item.typeName }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-dropdown @command="handlePersonal">
        <span class="el-dropdown-link" :class="single ? 'is-disabled': ''"><i class="el-icon-user" /> 分配人员<i class="el-icon-arrow-down el-icon--right" /> </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item v-for="(item, index) in UserTypeList" :key="index" :disabled="single" :command="beforeHandleCommand(item)">
            {{ item.typeName }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-col :md="12" :lg="14" :xl="17" class="personal-type">
        <span>{{ proName }}</span>
        <el-button icon="el-icon-arrow-left" size="mini" @click="handleReturn()">返回</el-button>
      </el-col>
    </el-row>
    <!-- 表格展示start -->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="tableData"
      :row-style="rowClass"
      stripe
      class="table-list"
      :class="highLevelSet===true ? (needTagsView===true ? 'el-body-page-roll-tag-height' : 'el-body-page-roll-height') :
        (needTagsView===true ? 'el-body-page-roll-tag' : 'el-body-page-roll')"
      @selection-change="handleSelectionChange"
      @row-click="rowChecked"
    >
      <el-table-column type="selection" width="38" align="center" />
      <el-table-column type="index" label="序号" width="51" align="center" />
      <el-table-column
        prop="explorationCode"
        label="勘探点编号"
        min-width="160"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="explorationType"
        label="勘探点类型"
        min-width="120"
        align="center"
        :formatter="setExplorationType"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="x"
        label="坐标经度"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="y"
        label="坐标纬度"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="elevation"
        label="高程(m)"
        min-width="100"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        prop="startTime"
        label="开孔时间"
        align="center"
        min-width="150"
      />
      <el-table-column
        prop="endTime"
        label="终孔时间"
        align="center"
        min-width="150"
      />
      <!--      <el-table-column-->
      <!--        prop="repair"-->
      <!--        label="补勘"-->
      <!--        align="center"-->
      <!--        min-width="150"-->
      <!--      >-->
      <!--        <template slot-scope="{row}">-->
      <!--          <span v-if="row.repair ==='0'">—</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--<el-table-column
        label="已确认项"
        min-width="150 "
        align="center"
        prop="status"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.explorationCode">
            <span class="file-icon active"><svg-icon class="icon" icon-class="equipment" />设备</span>
            <span class="file-icon active"><svg-icon class="icon" icon-class="personal" />人员</span>
          </div>
        </template>
      </el-table-column>-->
    </el-table>
    <!-- 表格展示end-->

    <!-- 分页器 -->
    <pagination
      class="pagination-container"
      :total="total"
      :page.sync="filters.pageNum"
      :limit.sync="filters.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
/** 页面接口 start */
import { listExplorationNoPermission } from '@/api/projectManage/project/exploration'
import { personalTypeFixed } from '@/api/superviseBaseInfo/typeManage/organizationType/index'
import { fixedEquipmentType } from '@/api/superviseBaseInfo/typeManage/equipmentType/index'
/** 页面接口 end */

import { mapState } from 'vuex'
export default {
  name: 'SupplierEquipment',
  components: {
  },
  data() {
    return {
      proName: '', // 项目名称
      UserTypeList: [], // 人员类型
      EquipmentTypeList: [], // 设备类型
      // 筛选条件
      highLevelSet: false, // 高级设置显示隐藏
      filters: {
        pageNum: 1,
        pageSize: 20,
        drillHole: '', // 勘探点类型
        explorationCode: '', // 勘探点编号
        explorationStatus: '1' // 勘探点状态
      },
      /* 列表 start*/
      total: 0, // 分页总条数
      single: true, // 非单个禁用
      selectRow: [], // 高亮样式
      multipleSelection: [], // 选中表格行
      loading: false, // 列表加载
      tableData: [], // 表格数据
      /* 列表 end*/
      explorationTypeList: [
        { value: '', label: '全部' },
        { value: '0', label: '钻探' },
        { value: '1', label: '静探' }
      ]
    }
  },
  computed: {
    ...mapState({
      needTagsView: (state) => state.settings.tagsView,
      explorationType: state => state.basicInfo.explorationType, // 勘探点类型全部
      explorationStatus: state => state.basicInfo.ExplorationStatusList
    }),
    // 高级搜索显示隐藏
    handleTagShow() {
      return this.highLevelSet
    }
  },
  mounted() {
    this.filters.proId = this.$store.state.basicInfo.proId
    this.proName = this.$route.query.proName
    this.getList()
    this.getSupperType()
    this.getEquipmentType()
  },
  methods: {
    // 回显勘探点类型
    setExplorationType(row) {
      return this.selectDictLabel(this.explorationType, row.explorationType)
    },
    // 获取人员类型
    async getSupperType() {
      const { data } = await personalTypeFixed()
      this.UserTypeList = data
    },
    // 获取设备类型
    async getEquipmentType() {
      const { data } = await fixedEquipmentType()
      this.EquipmentTypeList = data
    },
    // 获取数据
    async getList() {
      this.loading = true
      try {
        const { data: { rows, total }} = await listExplorationNoPermission(this.filters)
        this.loading = false
        this.tableData = rows
        this.total = total
        // this.addTaleData()
      } catch {
        this.loading = false
      }
    },
    // list表格填充空白行
    addTaleData() {
      if (this.tableData.length < this.fristPageSize) {
        const arr = {}
        this.tableData.push(arr)
        this.addTaleData()
      }
    },
    rowChecked(row) {
      const selectData = this.multipleSelection
      this.$refs.multipleTable.clearSelection()
      if (selectData.length === 1) {
        selectData.forEach((item) => {
          // 判断 如果当前的一行被勾选, 再次点击的时候就会取消选中
          if (item === row) {
            this.$refs.multipleTable.toggleRowSelection(row, false)
          } else {
            this.$refs.multipleTable.toggleRowSelection(row, true)
          }
        })
      } else {
        this.$refs.multipleTable.toggleRowSelection(row, true)
      }
    },
    // 点击表格前面选框时触发的事件
    handleSelectionChange(val) {
      if (JSON.stringify(val[0]) === '{}') {
        this.$refs.multipleTable.clearSelection()
        val = []
      }
      if (val.length === 1) {
        this.single = false
      } else {
        this.single = true
      }
      this.selectRow = []
      this.multipleSelection = val
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((item, index) => {
          this.selectRow.push(this.tableData.indexOf(item))
        })
      }
      if (val.length > 1) {
        this.$refs.multipleTable.clearSelection()
        this.$refs.multipleTable.toggleRowSelection(val.pop())
      }
    },
    // 高亮样式
    rowClass({ row, rowIndex }) {
      if (this.selectRow.includes(rowIndex)) {
        return { 'background-color': 'rgba(185,221,249,.75)' }
      }
    },
    /* 按钮 Start */
    // 搜索方法
    handleQuery() {
      this.filters.pageNum = 1
      this.getList()
    },
    // 重置搜索
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 详情
    handleDetail() {
      this.dialogTitle = '钻孔详情'
      const id = this.multipleSelection[0]
      this.$refs.detailDialog.handleAdd(this.dialogTitle, id)
    },
    // 配置人员
    handlePersonal(command) {
      this.$store.commit('basicInfo/SET_ExplorationId', this.multipleSelection[0].id)
      this.$router.push({
        path: '/newProject/projectExploration-Personal',
        query: {
          explorationCode: this.multipleSelection[0].explorationCode,
          explorationType: this.multipleSelection[0].explorationType,
          personType: command.typeNum,
          personTypeName: command.typeName
        }
      })
    },
    beforeHandleCommand(command) {
      return command
    },
    // 配置设备
    handleEquipment(command) {
      this.$store.commit('basicInfo/SET_ExplorationId', this.multipleSelection[0].id)
      console.log(command)
      this.$router.push({
        path: '/newProject/projectExploration-Equipment',
        query: {
          explorationCode: this.multipleSelection[0].explorationCode,
          explorationType: this.multipleSelection[0].explorationType,
          equipmentType: command.typeNum,
          equipmentTypeName: command.typeName
        }
      })
    },
    // 返回
    handleReturn() {
      this.$router.push({
        path: '/newProject/distributionList'
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .file-icon{
    color:#999999;
    margin-right: 10px;
    font-size: 12px;
    &.active{
      color:#0a7fff;
    }
    .icon{
      font-size: 14px;
    }
  }
</style>

